/**
*
* @file ipcMessage.h
*
* @brief inter-process-communication message declaration
*
* Corresponds to SIO_Processor.asn1
*
* Copyright © 2011 HID Corporation.  All rights reserved.
*
* This software is protected by copyright law and international treaties.
* Any unauthorized reproduction, distribution or use of the software is prohibited.
*
*/

#ifndef _ipcMessage_h
#define _ipcMessage_h
#include "stdint.h"
#include"types.h"
/*
struct _IPC_HEADER {
    uint8_t source;
    uint8_t destination;
    uint8_t replyTo;
    uint8_t priority;
    uint16_t timeout;
} PACK_STRUCT_END;
*/
#pragma pack(1)

struct _NAD_PCB_LEN {
    uint8_t nad;
    uint8_t pcb;
    uint8_t len;
};
typedef struct _NAD_PCB_LEN NAD_PCB_LEN;
#pragma pack()

struct _IPC_HEADER {
    uint8_t source;
    uint8_t destination;
    uint8_t replyTo;
    uint8_t priority;
    uint16_t timeout;
};
typedef struct _IPC_HEADER IPC_HEADER;

struct _IPC_MESSAGE {
    uint16_t length;
    IPC_HEADER header;
    uint8_t payload[1];
} ;//PACK_STRUCT_END

typedef struct _IPC_MESSAGE IPC_MESSAGE;

#define MAX_PRIORITY                            0
#define MIN_PRIORITY                            10

// Payload Class (choice)
#define PAYLOAD_SAM_COMMAND                     0
#define PAYLOAD_HF_COMMAND                      1
#define PAYLOAD_CORE_COMMAND                    5
#define PAYLOAD_BLE_COMMAND                     0x15

#define PAYLOAD_RESPONSE                        29
#define PAYLOAD_ERROR_RESPONSE                  30

// Response Class(choice)
#define RESPONSE_HFCOMMAND                      0
#define RESPONSE_CORECOMMAND                    2
#define RESPONSE_SAMCOMMAND						10
#define RESPONSE_BLECOMMAND						0x16

#define IPC_NODEID_NULL                         0
#define IPC_NODEID_ROUTER                       1
#define IPC_NODEID_SAM                  		10
#define IPC_NODEID_HF_INTERFACE         		20
#define IPC_NODEID_EXTERNAL_APP         		68
//	#define IPC_NODEID_EXTERNAL_APP         		01
#define IPC_NODEID_DIRECT_ACCESS_SAM    		88
#define IPC_NODEID_BLE							0x2D
#define IPC_NODEID_I2C							0x54

// Core commands

// Core-Command Type (choice)
#define CORECOMMAND_RESET                       2
#define CORECOMMAND_RESET_SAM                   5

// SAM commands

// SAM-Command Type (choice)
#define SAMCOMMAND_GET_CONTENT_ELEMENT          1
#define SAMCOMMAND_GET_VERSION_INFO             2
#define SAMCOMMAND_PROCESS_CARD_API             5
#define SAMCOMMAND_SET_DETECTED_CARD_INFO       13
#define SAMCOMMAND_SECURE_CHANNEL_INIT_AUTH		15
#define SAMCOMMAND_SECURE_CHANNEL_CONTINUE_AUTH	16
#define SAMCOMMAND_SECURE_CHANNEL_TERMINATE		17
#define SAMCOMMAND_TRACK_CARD                   18
#define SAMCOMMAND_ANTI_COLLISION               0x17

#define IMPLICIT_FORMAT_PAC_BITS 				4

// CARD API Type (choice)
#define CARD_API_PICOPASS                       0
#define CARD_API_PCSC_CONTACTLESS               3
#define CARD_API_TCL_TRANSMIT		            4
#define CARD_API_LOAD_KEY						5

// PICOPASS API (choice)
#define CARD_API_PICOPASS_SELECT                0
#define CARD_API_PICOPASS_READ_BLOCK            1
#define CARD_API_PICOPASS_READ_4BLOCK           2
#define CARD_API_PICOPASS_READ_CHECK            3
#define CARD_API_PICOPASS_MUTUAL_AUTH           4
#define CARD_API_PICOPASS_WRITE_BLOCK           5

// TCL TRANSMIT RESPONSE (choice)
#define TCL_RESPONSE_DATA						0
#define TCL_RESPONSE_RF_STATUS					1
#define TCL_RESPONSE_ACK						2

// SamResponseTrackCard ::= ENUMERATED
#define CARD_TRACKING_NO_VALID_CARD_INFO        0
#define CARD_TRACKING_NO_CARD_IN_FIELD          1
#define CARD_TRACKING_CARD_IN_FIELD             2

// HF commands

// HF-Command Type (choice)
#define HFCOMMAND_TRANSMIT                      1
#define HFCOMMAND_SET_FIELD_OFF                 2

// HF-Command Response type (choice)
#define RESPONSE_HFCOMMAND_RX                   0
#define RESPONSE_HFCOMMAND_ACK                  2

// HF-Command RX Response content (context)
#define HFCOMMAND_RESPONSE_RX_DATA              0
#define HFCOMMAND_RESPONSE_RX_RFSTATUS          1
#define HFCOMMAND_RESPONSE_RX_NUM_BITS          2

// HFCommandTransmit dataRateOut & dataRateIn tx & rx speed
#define ASN1_RF_SPEED_NOT_SET                   0x00
#define ASN1_RF_SPEED_26K                       0x01
#define ASN1_RF_SPEED_106K                      0x02
#define ASN1_RF_SPEED_212K                      0x03
#define ASN1_RF_SPEED_424K                      0x04
#define ASN1_RF_SPEED_848K                      0x05

// Error Response (sequence)
#define RESPONSE_ERROR_CODE                     0
#define RESPONSE_ERROR_DATA                     1

// flags
#define ASN1_RF_FLAGS_NONE                      0x0000
#define ASN1_RF_FLAGS_TX_ONLY_SOF               0x0001 // only transmit SOF with no data
#define ASN1_RF_FLAGS_TX_ONLY_EOF               0x0002 // only transmit EOF with no data
#define ASN1_RF_FLAGS_RX_ONLY_SOF               0x0004 // only expect to receive SOF with no data
#define ASN1_RF_FLAGS_RX_ONLY_EOF               0x0008 // only expect to receive EOF with no data
#define ASN1_RF_FLAGS_RX_NO_SOF                 0x0010 // no receive SOF, even if framing is enabled
#define ASN1_RF_FLAGS_RX_NO_EOF                 0x0020 // no receive EOF, even if framing is enabled
#define ASN1_RF_FLAGS_TX_PARITY                 0x0040 // enable tx parity
#define ASN1_RF_FLAGS_RX_PARITY                 0x0080 // enable rx parity
#define ASN1_RF_FLAGS_PARITY_EVEN               0x0100 // enable even parity (default is odd parity)
#define ASN1_RF_FLAGS_TX_CRC                    0x0200 // transmit CRC bytes
#define ASN1_RF_FLAGS_RX_CRC                    0x0400 // receive and check CRC bytes
/*--------------------------------------------------------------------------------------------------------*/
// BLE Command

// BLE-Command Type (choice)
#define BLECOMMAND_TRANSMIT                      0x02
#define BLECOMMAND_GET_VERSION_2                 0x0C
#define BLECOMMAND_GET_PROPERTIES                0x04
#define BLECOMMAND_SET_CONFIG	                0x05

// BLE-Command Response type (choice)
#define RESPONSE_BLECOMMAND_RX                   0x02
#define RESPONSE_BLECOMMAND_GET_VERSION2         0x0C
#define RESPONSE_BLECOMMAND_PROPERTIES			0x04
#define RESPONSE_BLECOMMAND_SET_CONFIG			0x05


/*--------------------------------------------------------------------------------------------------------*/
// frame protocol
#define ASN1_FRAME_PROTOCOL_NONE                0 // rf field is turned off / no card found
#define ASN1_FRAME_PROTOCOL_ISO14443A           2
#define ASN1_FRAME_PROTOCOL_PICO15693           4
#define ASN1_FRAME_PROTOCOL_PICO14443B          5
#define ASN1_FRAME_PROTOCOL_BLE          		0x15

// transmission protocol
#define ASN1_TRANSMISSION_PROTOCOL_NONE         0
#define ASN1_TRANSMISSION_PROTOCOL_T0           1
#define ASN1_TRANSMISSION_PROTOCOL_T1TCL        2

// rxStatus
#define ASN1_RF_STATUS_OK                       0x0000 // all ok
#define ASN1_RF_STATUS_RX_ONLY_SOF              0x0001 // only SOF received
#define ASN1_RF_STATUS_FRAMING_ERROR            0x0002 // framing error or field failure during receive
#define ASN1_RF_STATUS_CRC_ERROR                0x0004 // error in receive CRC
#define ASN1_RF_STATUS_PARITY_ERROR             0x0008 // error in receive parity
#define ASN1_RF_STATUS_COLLISION                0x0010 // collision detected in receive data
#define ASN1_RF_STATUS_TIMEOUT                  0x0020 // timed out
#define ASN1_RF_STATUS_BUFFER_OVERRUN           0x0040 // fifo overrun

#endif // _ipcMessage_h

///
